﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using MySql.Data.Types;

namespace GirisSayfasi
{
    public partial class OgretmenDersDersArama : Form
    {
        public static string Ders_Kodu;
        public OgretmenDersKayit anaform;
        MySqlConnection baglan = Connection.baglan;

        public OgretmenDersDersArama()
        {
            InitializeComponent();
        }

        private void OgretmenDersDersArama_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                this.Close();
            }
            if (e.KeyCode == Keys.Enter)
            {
                lstDersBilgileri.Items.Clear();
                baglan.Open();
                MySqlCommand cmd1 = new MySqlCommand("SELECT DersKodu, DersIsmi FROM derslistesi Where DersIsmi LIKE  @txtDersIsmi  '%'", baglan);
                cmd1.Parameters.AddWithValue("@txtDersIsmi", txtDersIsmi.Text);
                int sayi = Convert.ToInt32(cmd1.ExecuteScalar());
                if (sayi != 0)
                {

                    MySqlDataReader oku1 = cmd1.ExecuteReader();
                    if (oku1.HasRows)
                    {
                        while (oku1.Read())
                        {
                            ListViewItem lst = new ListViewItem();
                            lst.Text = oku1["DersIsmi"].ToString();
                            lst.Tag = oku1["DersKodu"];
                            lstDersBilgileri.Items.Add(lst);

                        }
                    }

                }
                baglan.Close();
            }


        }

        private void OgretmenDersDersArama_Activated(object sender, EventArgs e)
        {
            lstDersBilgileri.Items.Clear();
            txtDersIsmi.Clear();
            txtDersIsmi.Focus();
        }

        private void lstDersBilgileri_DoubleClick(object sender, EventArgs e)
        {
            OgretmenDersKayit frm2 = (OgretmenDersKayit)Application.OpenForms["OgretmenDersKayit"];
            ///OgrenciKayit frm2 = new OgrenciKayit();
            frm2.mskDersKodu.Text = lstDersBilgileri.SelectedItems[0].Tag.ToString();
            this.Hide();

        }
    }
}
